package gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EtchedBorder;

import controller.KioskoApp;

public class MainW {

	private JFrame frmAccounting;
	private JTextField txtAmount;
	private JPanel calendarPanel;
	private JButton btnSaveCash;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainW window = new MainW();
					window.frmAccounting.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public MainW() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		 try {
			UIManager.setLookAndFeel(
			 UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (InstantiationException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IllegalAccessException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (UnsupportedLookAndFeelException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		frmAccounting = new JFrame();
		frmAccounting.setTitle("Contabilidad");
		frmAccounting.setBounds(100, 100, 400, 500);
		frmAccounting.setResizable(false);
		frmAccounting.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		frmAccounting.addWindowListener(new WindowListener() {
			
			@Override
			public void windowOpened(WindowEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowIconified(WindowEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowDeiconified(WindowEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowDeactivated(WindowEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowClosing(WindowEvent arg0) {
				try {
					KioskoApp.saveChanges();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			
			@Override
			public void windowClosed(WindowEvent arg0) {
				// TODO Auto-generated method stub
				 
			}
			
			@Override
			public void windowActivated(WindowEvent arg0) {
				// TODO Auto-generated method stub
				
			}
		});
		
		JTabbedPane mainPanel = new JTabbedPane(JTabbedPane.TOP);
		frmAccounting.getContentPane().add(mainPanel, BorderLayout.CENTER);
		
		JPanel account = new JPanel();
		mainPanel.addTab("Caja", null, account, null);
		
		JPanel topPanel = new JPanel();
		topPanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		
		JPanel botPanel = new JPanel();
		botPanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		GroupLayout gl_account = new GroupLayout(account);
		gl_account.setHorizontalGroup(
			gl_account.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, gl_account.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_account.createParallelGroup(Alignment.TRAILING)
						.addComponent(topPanel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 369, Short.MAX_VALUE)
						.addComponent(botPanel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 369, Short.MAX_VALUE))
					.addContainerGap())
		);
		gl_account.setVerticalGroup(
			gl_account.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_account.createSequentialGroup()
					.addContainerGap()
					.addComponent(topPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addGap(18)
					.addComponent(botPanel, GroupLayout.PREFERRED_SIZE, 252, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(17, Short.MAX_VALUE))
		);
		
		JLabel lblSummaryMonth = new JLabel("Resumen mes:");
		lblSummaryMonth.setFont(new Font("Tahoma", Font.BOLD, 18));
		
		JButton btnSummaryMonth = new JButton("");
		btnSummaryMonth.setFont(new Font("Tahoma", Font.PLAIN, 13));
		
		JLabel lblSummaryYear = new JLabel("Resumen a\u00F1o:");
		lblSummaryYear.setFont(new Font("Tahoma", Font.BOLD, 18));
		
		JButton btnSummaryYear = new JButton("");
		btnSummaryYear.setFont(new Font("Tahoma", Font.PLAIN, 13));
		
		JButton btnSummaryMonthNext = new JButton(">");
		btnSummaryMonthNext.setFont(new Font("Tahoma", Font.PLAIN, 13));
		
		JButton btnSummaryMonthPrev = new JButton("<");
		btnSummaryMonthPrev.setFont(new Font("Tahoma", Font.PLAIN, 13));
		
		JButton btnSummaryYearNext = new JButton(">");
		btnSummaryYearNext.setFont(new Font("Tahoma", Font.PLAIN, 13));
		
		JButton btnSummaryYearPrev = new JButton("<");
		btnSummaryYearPrev.setFont(new Font("Tahoma", Font.PLAIN, 13));
		GroupLayout gl_botPanel = new GroupLayout(botPanel);
		gl_botPanel.setHorizontalGroup(
			gl_botPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_botPanel.createSequentialGroup()
					.addGap(56)
					.addGroup(gl_botPanel.createParallelGroup(Alignment.TRAILING, false)
						.addComponent(btnSummaryYearPrev, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(btnSummaryMonthPrev, GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_botPanel.createParallelGroup(Alignment.TRAILING, false)
						.addComponent(btnSummaryYear, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(btnSummaryMonth, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(lblSummaryMonth, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(lblSummaryYear, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_botPanel.createParallelGroup(Alignment.LEADING, false)
						.addComponent(btnSummaryYearNext, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(btnSummaryMonthNext, GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE))
					.addGap(57))
		);
		gl_botPanel.setVerticalGroup(
			gl_botPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_botPanel.createSequentialGroup()
					.addGap(20)
					.addComponent(lblSummaryMonth)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_botPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnSummaryMonth, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnSummaryMonthNext, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnSummaryMonthPrev, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE))
					.addGap(34)
					.addComponent(lblSummaryYear)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_botPanel.createParallelGroup(Alignment.LEADING)
						.addComponent(btnSummaryYear, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnSummaryYearNext, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnSummaryYearPrev, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(66, Short.MAX_VALUE))
		);
		botPanel.setLayout(gl_botPanel);
		
		JLabel lblCash = new JLabel("Caja:");
		lblCash.setFont(new Font("Tahoma", Font.BOLD, 18));
		
		JLabel lblDate = new JLabel("Fecha:");
		lblDate.setFont(new Font("Tahoma", Font.BOLD, 18));
		
		calendarPanel = new JPanel();
		
		txtAmount = new JTextField("100 \u20AC");
		txtAmount.setFont(new Font("Tahoma", Font.PLAIN, 14));
		txtAmount.setHorizontalAlignment(SwingConstants.CENTER);
		
		btnSaveCash = new JButton("X");
		GroupLayout gl_topPanel = new GroupLayout(topPanel);
		gl_topPanel.setHorizontalGroup(
			gl_topPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_topPanel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_topPanel.createParallelGroup(Alignment.LEADING)
						.addComponent(lblCash)
						.addComponent(lblDate))
					.addGroup(gl_topPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_topPanel.createSequentialGroup()
							.addGap(19)
							.addComponent(txtAmount, GroupLayout.PREFERRED_SIZE, 187, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(btnSaveCash, GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE))
						.addGroup(gl_topPanel.createSequentialGroup()
							.addGap(18)
							.addComponent(calendarPanel, GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)))
					.addContainerGap(22, GroupLayout.PREFERRED_SIZE))
		);
		gl_topPanel.setVerticalGroup(
			gl_topPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_topPanel.createSequentialGroup()
					.addContainerGap(37, Short.MAX_VALUE)
					.addGroup(gl_topPanel.createParallelGroup(Alignment.TRAILING, false)
						.addComponent(calendarPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(lblDate, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
					.addGap(29)
					.addGroup(gl_topPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblCash)
						.addComponent(txtAmount, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnSaveCash, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE))
					.addGap(22))
		);
		topPanel.setLayout(gl_topPanel);
		account.setLayout(gl_account);
		
		JPanel lottery = new JPanel();
		mainPanel.addTab("<html>Loter&iacute;a</html>", null, lottery, null);
	}
	public JTextField getTxtAmount() {
		return txtAmount;
	}
	public JPanel getCalendarPanel() {
		return calendarPanel;
	}
	public JFrame getFrmAccounting() {
		return frmAccounting;
	}
	public JButton getBtnSaveCash(){
		return btnSaveCash;
	}
	public JButton getBtnSaveCash(){
		return btnSaveCash;
	}
}
